﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DBUtility;

namespace TierApplication
{
    public partial class P_DDCODE
    {
        public enum DDType
        {
            Bandwidth,
            LifeTime,
            CategoryId,
            ProductItemStatus,
            ImpStatus,
            OrderStatus,
            CancelReason,
            AuthResult
        }

        public static DataSet GetListByType(string sDdtype)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select CodeID,CodeName,OrderID,Remark ");
            strSql.Append(" FROM P_DDCode ");
            if (sDdtype.Trim() != "")
            {

                strSql.Append(" where DDType = '" + sDdtype + "' ORDER BY OrderID");
            }
            return DbHelperOra.Query(strSql.ToString());
        }

        public static string GetCodeIDByCodeName(string sDdtype, string sCodeName)
        {
            string sCodeID;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append("CodeID");
            strSql.Append(" from P_DDCode ");
            strSql.Append(" where DDType = '" + sDdtype + "'");
            strSql.Append(" and CodeName='" + sCodeName + "'");
            DataSet ds = DbHelperOra.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                sCodeID = ds.Tables[0].Rows[0]["CodeID"].ToString();
            }
            else
                sCodeID = "";

            return sCodeID;
        }

        public static string GetCodeNameByCodeID(string sDdtype, string sCodeID)
        {
            string sCodeName;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append("CodeName");
            strSql.Append(" from P_DDCode ");
            strSql.Append(" where DDType = '" + sDdtype + "'");
            strSql.Append(" and CodeID='" + sCodeID + "'");
            DataSet ds = DbHelperOra.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                sCodeName = ds.Tables[0].Rows[0]["CodeName"].ToString();
            }
            else
                sCodeName = "";

            return sCodeName;
        }
    }
}
